﻿using ACompany.OrderProcessing.Infrastructure.Query;
using NHibernate;
using NHibernate.Criterion;

namespace ACompany.OrderProcessing.NHibernateRepository
{
    public class QueryTranslator
    {
        public static ICriteria GetCriteriFrom(ICriteria criteria, Query query)
        {
            foreach (Criteria cr in query.Criteria)
            {
                switch (cr.CriteriaOperator)
                {
                    case CriteriaOperator.Like:
                        criteria.Add(Expression.Like(cr.PropertyName, string.Format("{0}%", cr.Value)));
                        break;
                    case CriteriaOperator.Equals:
                        criteria.Add(Expression.Eq(cr.PropertyName, cr.Value));
                        break;
                }

            }
            return criteria;
        }
    }
}
